<template>
  <el-container>
    <el-header>
      <div class="hh">
        <i class="el-icon-platform-eleme"></i><span>电商后台管理项目</span>
      </div>
      <div class="login">
        <span>admin</span>
        <el-button class="Out" type="info" @click="clear">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="iscollapse ? '64px' : '200px' ">
          <div class="coll"><i class="el-icon-s-operation" @click="zhedie"></i></div>
          <!-- unique-opened 只展开一个 
                router 是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转
          -->
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="rgb(51, 51, 51)"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          :collapse = "iscollapse"
          :collapse-transition = "false"
          router
        >
          <el-submenu  v-for="item in menus" :key="item.id" :index="item.id+''">
            <template slot="title">
              <i :class="iconObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item v-for="son in item.children" :key="son.id" :index="'/'+son.path">
                  <i class="el-icon-document-copy"></i>
                  {{son.authName}}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      menus: [],
      iconObj:{
          125:'el-icon-menu',
          103:'el-icon-s-tools',
          101:'el-icon-s-goods',
          102:'el-icon-s-order',
          145:'el-icon-s-data'
      },
      iscollapse: false
    };
  },
  created(){
      this.getMenuList();
  },
  methods: {
    clear() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList(){
        const {data:res} = await this.$http.get('menus');
        console.log(res);
        this.menus = res.data;
    },
    zhedie(){
        if(this.iscollapse){
            this.iscollapse = false
        }else {
            this.iscollapse = true
        }
    }
  },
};
</script>
<style scoped>
.el-container {
  height: 100%;
}
.el-header {
  background: rgba(37, 37, 38);
  position: relative;
}
.el-aside {
  background: rgb(51, 51, 51);
  border: 0;

}
.el-main {
  background: rgb(243, 243, 240);
}
.login {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 30px;
  color: #fff;
}
.login span {
  margin-right: 20px;
}
.hh {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 20px;
  color: #fff;
  font-size: 24px;
}
.hh > span {
  margin-left: 10px;
}
.coll {
    display: inline-block;
    width: 100%;
    height: 36px;
    background: rgba(177, 173, 173, 0.1);
    border: 0;
    position: relative;
}
.coll>i {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
}
.el-menu {
    border: 0;
}
</style>